<template>
  <div class="wrap bg-w">
    <ul class="sort-header container bg-w fx-h-c">
      <li
        class="item cs"
        :class="{ active: activeIndex === i }"
        v-for="(item, i) in sorts"
        :key="i"
        @click="changeAcitveIndex(i)"
      >
        <span>{{ item }}</span>
      </li>
    </ul>
  </div>
</template>

<script>
import { setSessionStorage,  getSessionStorage} from "@/utils/utils";
export default {
  name: "SortHeader",
  data() {
    return {
      sorts: ["综合", "文章", "用户", "标签", "小册"],
      activeIndex: +getSessionStorage('searchActiveIndex') || 0,
    };
  },
  methods: {
    changeAcitveIndex(i) {
      this.activeIndex = i;
      switch (i) {
        case 0:
          setSessionStorage("tag", 0);
          this.$bus.$emit("getNewSeachContent");
          break;
        case 1:
          setSessionStorage("tag", 1);
          this.$bus.$emit("getNewSeachContent");
          break;
        case 2:
          setSessionStorage("tag", 2);
          this.$bus.$emit("getNewSeachContent");
      }
      setSessionStorage("searchActiveIndex", i);
    },
  },
  created() {
     setSessionStorage("tag", this.activeIndex);
  },
};
</script>

<style lang="scss" scoped>
.wrap {
  .sort-header {
    height: 5rem;
  }
  .item {
    margin-right: 3.3rem;
    font-size: 1.4rem;
    &.active {
      color: #007fff;
    }
  }
}
</style>